using System;
using System.Text.RegularExpressions;
using System.Web.Mvc;

namespace Chatu.ControlLider.Web.Models.Domain
{
    public class Employee : EmployeeSummary
    {
        public Guid UserID { get; set; }
        public DateTime? BirthDate { get; set; }
        public DateTime? HireDate { get; set; }
        public int EducationLevelID { get; set; }
        public int TypeID { get; set; }
        public string Address { get; set; }
        public string Phone { get; set; }

        public bool Validate(ModelStateDictionary modelState)
        {
            Regex regex = new Regex(@"\d{8}");

            if (string.IsNullOrEmpty(Cedula))
                modelState.AddModelError("Cedula", "Cedula es requerida");
            else if (!regex.IsMatch(Cedula))
                modelState.AddModelError("Cedula", "Cedula es invalida");

            if (string.IsNullOrEmpty(FirstName))
                modelState.AddModelError("FirstName", "Nombre es requerido");

            if (string.IsNullOrEmpty(LastName))
                modelState.AddModelError("LastName", "Apellido es requerido");

            if (!BirthDate.HasValue)
                modelState.AddModelError("BirthDate", "Fecha de nacimiento es requerida");

            if (EducationLevelID == 0)
                modelState.AddModelError("EducationLevelID", "Grado de Instruccion es requerido");

            if (!HireDate.HasValue)
                modelState.AddModelError("HireDate", "Fecha de Ingreso es requerida");

            if (TypeID == 0)
                modelState.AddModelError("TypeID", "Tipo de contrato es requerido");

            if (string.IsNullOrEmpty(JobTitle))
                modelState.AddModelError("JobTitle", "Cargo es requerido");

            if (string.IsNullOrEmpty(Address))
                modelState.AddModelError("Address", "Direccion es requerida");

            if (string.IsNullOrEmpty(Phone))
                modelState.AddModelError("Phone", "Telefono es requerido");

            return modelState.IsValid;
        }
    }
}